package com.basic.technology.study.introduction.thread.communication;

public class YieldTest {

    static int num = 0;

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
            System.out.println(System.currentTimeMillis() + ",start " + Thread.currentThread().getName());
            for (int i = 0; i < 10; i++) {
                num++;
                try {
                    Thread.sleep(200);
                    if (i == 6) {
                        System.out.println("yield=====");
                        Thread.yield();
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("----" + System.currentTimeMillis());
            }
            System.out.println(System.currentTimeMillis() + ",end " + Thread.currentThread().getName());
        });
        t1.start();
       Thread.sleep(2000);

        System.out.println(System.currentTimeMillis() + ",num = " + num);
    }
}
